package com.ruoyi.study.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.study.domain.StyMysql;
import com.ruoyi.study.service.IStyMysqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 数据库信息Controller
 * 
 * @author dwb
 * @date 2024-09-03
 */
@RestController
@RequestMapping("/mysql")
public class StyMysqlController extends BaseController
{
    @Autowired
    private IStyMysqlService styMysqlService;

    /**
     * 查询数据库信息列表
     */
    @RequiresPermissions("study:mysql:list")
    @GetMapping("/list")
    public TableDataInfo list(StyMysql styMysql)
    {
        startPage();
        List<StyMysql> list = styMysqlService.selectStyMysqlList(styMysql);
        return getDataTable(list);
    }

    /**
     * 导出数据库信息列表
     */
    @RequiresPermissions("study:mysql:export")
    @Log(title = "数据库信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StyMysql styMysql)
    {
        List<StyMysql> list = styMysqlService.selectStyMysqlList(styMysql);
        ExcelUtil<StyMysql> util = new ExcelUtil<StyMysql>(StyMysql.class);
        util.exportExcel(response, list, "数据库信息数据");
    }

    /**
     * 获取数据库信息详细信息
     */
    @RequiresPermissions("study:mysql:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(styMysqlService.selectStyMysqlById(id));
    }

    /**
     * 新增数据库信息
     */
    @RequiresPermissions("study:mysql:add")
    @Log(title = "数据库信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StyMysql styMysql)
    {
        return toAjax(styMysqlService.insertStyMysql(styMysql));
    }

    /**
     * 修改数据库信息
     */
    @RequiresPermissions("study:mysql:edit")
    @Log(title = "数据库信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StyMysql styMysql)
    {
        return toAjax(styMysqlService.updateStyMysql(styMysql));
    }

    /**
     * 删除数据库信息
     */
    @RequiresPermissions("study:mysql:remove")
    @Log(title = "数据库信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(styMysqlService.deleteStyMysqlByIds(ids));
    }
}
